﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Web.Routing;
using System.Web.Mvc;
namespace JULONG.WEB.Library.Account
{
    public abstract class absAuthority
    {
        /// <summary>
        /// 过滤模式 false：黑名单 true：白名单
        /// </summary>
        public bool filterModel = false;

        /// <summary>
        /// 路由名单
        /// </summary>
        public List<routeForFilter> routeList = new List<routeForFilter>();

        /// <summary>
        /// 得到是否有权限
        /// </summary>
        /// <returns></returns>
        public abstract bool isAuthority(ActionExecutingContext filterContext);

        /// <summary>
        /// 得到路由名
        /// </summary>
        /// <returns></returns>
        public abstract string getRouteName();

        /// <summary>
        /// 得到路由名
        /// </summary>
        /// <returns></returns>
        public abstract object getLoginRouteValue();

        /// <summary>
        /// 登录未成功跳转之前的一些处理
        /// </summary>
        /// <param name="filterContext"></param>
        public abstract void onLoginResultBegin(ActionExecutingContext filterContext);

        public virtual string errorInfo { get { return "请重新登录"; } }

        /// <summary>
        /// 无权限时返回的页面(登录页面)
        /// </summary>
        /// <param name="filterContext"></param>
        /// <returns></returns>
        public RedirectToRouteResult loginResult(ActionExecutingContext filterContext)
        {
            onLoginResultBegin(filterContext);
            var loginRouteValue = new RouteValueDictionary(getLoginRouteValue());

            //得到请求URL
            var url = filterContext.HttpContext.Request.Path;
            if (string.IsNullOrWhiteSpace(url))
                url = loginOverUrl();

            loginRouteValue.Add("url", url);

            return new RedirectToRouteResult(getRouteName(), loginRouteValue, false);
        }

        /// <summary>
        /// 登入后如果未设置转向，则跳转到的页面url (栏目首页)
        /// </summary>
        /// <param name="filterContext"></param>
        /// <returns></returns>
        public abstract string loginOverUrl();

    }
}
